package com.wenyang.service.impl;

import com.wenyang.dao.UserDao;
import com.wenyang.entity.TabUser;
import com.wenyang.entity.VO.TabUserVo;
import com.wenyang.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @Author Zx
 * @Date 2024/3/29 8:25
 * @Version 1.0
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao userDao;

    /**
     * 分页查询所有用户信息
     * @param startIdx
     * @param size
     * @param username
     * @return
     */
    @Override
    public List<TabUserVo> listByPage(int startIdx, int size, String username) {
        List<TabUserVo> tabUsers = userDao.listByPage(startIdx, size, username);
//        for (TabUser tabUser : tabUsers) {
//            Date birthday = tabUser.getBirthday();
//            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
//            String format1 = format.format(birthday);
//            System.out.println(format1);
//        }
        return tabUsers;
    }


    /**
     * 添加用户信息
     * @param tabUser
     * @return
     */
    @Override
    public int saveUser(TabUser tabUser) {
        return userDao.saveUser(tabUser);
    }


    /**
     * 修改用户的状态
     * @param uid
     * @param status
     * @return
     */
    @Override
    public int updateStatus(Integer uid, String status) {
        return userDao.updateStatus(uid,status);
    }


    /**
     * 修改用户信息
     * @param tabUser
     * @return
     */
    @Override
    public int changeUser(TabUser tabUser) {
        return userDao.changeUser(tabUser);
    }


    /**
     * 根据id查询是否存在
     * @param uid
     * @return
     */
    @Override
    public TabUser findByUid(Integer uid) {
        return userDao.findByUid(uid);
    }


    /**
     * 查询是否有当前用户
     * @param username
     * @return
     */
    @Override
    public TabUserVo selectUsername(String username) {
        return userDao.selectUsername(username);
    }

    @Override
    public List<TabUser> findAll() {
        return userDao.findAll();
    }
}
